package com.ce.controller;


import com.ce.entity.ProductCategory;
import com.ce.service.ProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商品类别表 前端控制器
 * </p>
 *
 * @author ce
 * @since 2022-02-22
 */
@RestController
@RequestMapping("/product-category")
public class ProductCategoryController {
    @Autowired
    ProductCategoryService service;

    /**
     * 查询商品分类信息
     */
    @PostMapping("/getProductCategoryist")
    public List<ProductCategory> testSelect(ProductCategory productCategory){
        List<ProductCategory> productCategories = service.getList(productCategory);
        return productCategories;

    }

    /**
     * 删除商品分类信息
     */
    @DeleteMapping("/deleteProductCategory")
    public Integer deleteProductCategory(Integer id){
        Integer res =service.deleteById(id);
        return res;
    }

    /**
     * 添加商品分类
     */
    @PostMapping("/addProductCategory")
    public Map<String, String> insertProductCategory(HttpServletRequest request) throws ParseException {
        ProductCategory productCategory = new ProductCategory();
        productCategory.setCategoryName(request.getParameter("categoryName"));
        return service.addProductCategory(productCategory);
    }

    /**
     * 修改商品分类信息
     */
    @PostMapping("/updateProductCategory")
    public Map<String, String> updateProductCategory(HttpServletRequest request) throws ParseException {
        ProductCategory productCategory = new ProductCategory();
        productCategory.setId(Integer.parseInt(request.getParameter("id")));
        productCategory.setCategoryName(request.getParameter("categoryName"));
        System.out.println("jyt"+request.getParameter("categoryName"));
        return service.updateProductCategory(productCategory);
    }
}
